<template>
  <div class="content">
    <div class="content_title">
      专业信息
    </div>
    <div class="main_content" v-loading="loading">
      <div class="main_content_left">
        <el-image
          class="major_pic"
          fit="contain"
          :src="majorInfo.majorPic?majorInfo.majorPic:require('@/assets/images/major.png')"
          :preview-src-list="[majorInfo.majorPic?majorInfo.majorPic:require('@/assets/images/major.png')]"
          alt="加载失败"
        ></el-image>
      </div>
      <div class="main_content_right">
        <div class="content_lebal">
          <div class="title">
            专业名称：
          </div>
          <div class="content_value">
            {{ majorInfo.majorName }}
          </div>
        </div>
        <div class="content_lebal">
          <div class="title">
            专业简介：
          </div>
          <div class="content_textarea" v-html="renderedText"></div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getPost_major } from '@/api/schoolOrganization/organization'

export default {
  name: 'majorDetial',
  props: {
    majorId: {
      type: [String, Number],
      default: ''
    }
  },
  data() {
    return {
      loading: false,
      majorInfo: {}
    }
  },
  computed: {
    renderedText() {
      return this.majorInfo.content ? this.majorInfo.content.replace(/\n/g, '<br>') : '--'
    }
  },
  watch: {
    majorId: {
      handler() {
        this.getMajorDetial()
      },
      immediate: true
    }
  },
  methods: {
    async getMajorDetial() {
      this.loading = true
      let res = await getPost_major(this.majorId)
      if (res.code == 200) {
        this.loading = false
        this.majorInfo = res.data
      }
    }
  }
}
</script>

<style scoped lang="scss">
.content {
  width: 100%;
  display: flex;
  flex-direction: column;

  .content_title {
    color: #333333;
    font-size: 16px;
    font-weight: bold;
  }

  .main_content {
    margin-top: 10px;
    display: flex;
    align-items: center;

    &_left {
      padding: 10px;
      box-sizing: border-box;
      border-radius: 12px;
      background: white;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.08);

      .major_pic {
        width: 320px;
        height: 200px;
        border-radius: 12px;
      }
    }

    &_right {
      margin-left: 10px;

      .content_lebal {
        width: 100%;
        color: #999999;
        display: flex;
        margin: 10px 0;

        .title {
          min-width: 88px;
        }

        .content_value {
          color: #333333;
        }

        .content_textarea {
          width: 500px;
          height: 160px;
          overflow: auto;
          color: #333333;
          word-wrap: break-word; /* 当单词超出容器宽度时自动换行 */
        }
      }
    }
  }
}
</style>
